package cn.itcast.servlet;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TestServlet03
 */
public class TestServlet03 extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 1、得到ServletContext对象
	    ServletContext context = this.getServletContext();
	    // 2、获取全局的初始化参数
	    Enumeration<String> er = context.getInitParameterNames();
	    // 获取所有初始化参数名称的键值，根据键获取值
	    while (er.hasMoreElements()) {
	        String name = er.nextElement();
	        String value = context.getInitParameter(name);
	        System.out.println("初始化参数的名称：" + name);
	        System.out.println("名称对应的值：" + value);
	        
	    }
	    
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
